import React, { FC, useMemo, useState } from "react";

const UseMemoDemo: FC = () => { 
    console.log("初始化加载");
    
    const [num1, setNum1] = useState(10)
    const [num2, setNum2] = useState(20)
    const [num3,setNum3]=useState(100)
    const sum = useMemo(() => { 
        console.log(22222222222);
        
        return num1 + num2

    },[num1,num2])

    return (
        <div>
            总和:{sum}
       
            <p> num1:{num1}</p> <button onClick={() => { 
                setNum1(num1 + 1)
            }}>num1 +1</button>
            <p>  num2:{num2}</p><button onClick={() => { 
                setNum2(num2 + 1)
            }}>num2 +1</button>
            <p>num3:{num3}</p>
            <button onClick={() => { 
                setNum3(num3 + 1)
            }}>num3+1</button>
          
            

        </div>
    )

}

export default UseMemoDemo;